{% extends "base.html" %}
{% load staticfiles %}

{% block title %}{{ title }}{% endblock %}

{% block content %}
    <!-- Main content -->
    <body>
    <section class="content-header">
{#        <h1 style="margin-bottom: 10px">报单查询</h1>#}
        <div class="nav-tabs-custom">

            <ul class="nav nav-tabs">
                <li class="active" style="margin-top:10px"><a href="#fa-check" onclick="tabs(0)" data-toggle="tab">报单查询</a>
                </li>
            </ul>
            <div class="tab-content">
                <!--报单查询-->
                <div class="tab-pane active" id="fa-check">
                    <div class="div-query">
                        <div class="lbl-query"><span>交易日</span>
                            <input class="input-query" type="text" id="Tradingday">
                            <span id="tradingdaySpanInfo" style="color: red;font-size: 14px"></span>
                        </div>
                        <div class="lbl-query"><span>策略编号</span>
                            <input class="input-query" type="text" id="RuleID">
                        </div>
                        <div class="lbl-query"><span>报单内部编号</span>
                            <input class="input-query" type="text" id="OrderInnerID">
                        </div>
                        <div class="lbl-query"><span>交易账号</span>
                            <input class="input-query" type="text" id="AccountID">
                        </div>
                        <div class="lbl-query"><span>合约代码</span>
                            <input class="input-query" type="text" id="InstrumentID">
                        </div>
                        <div class="lbl-query"><span>挂单状态</span>
                            <select class="input-query" id="OrderStatus">
                                <option value=""></option>
                                <option value="0">全部成交</option>
                                <option value="1">部分成交</option>
                                <option value="3">未成交</option>
                                <option value="5">撤单</option>
                                <option value="6">订单已报入交易所未应答</option>
                                <option value="7">废单</option>
                                <option value="8">自成交废单</option>
                                <option value="a">未知</option>
                                <option value="b">尚未触发</option>
                                <option value="c">已触发</option>
                            </select></div>
                        <div class="lbl-query">
                            <button class="btn-query" onclick="orderSearchSelect()">查询
                            </button>
                        </div>
                    </div>
                    <table class="stc-" id="OrderSearch">
                    </table>
                </div>
            </div>
        </div>
    </section>
    </body>

{% endblock %}

{% block scripts %}
    <script type="text/javascript">

        // 当前日期YYMMDD，并tradingday默认显示当天
        function GDate() {
            var myDate = new Date;
            var year = myDate.getFullYear(); //获取当前年
            var mon = myDate.getMonth() + 1; //获取当前月
            var date = myDate.getDate()
            if (mon < 10) {
                mon = "0" + mon
            }
            if (date < 10) {
                date = "0" + date
            }

            return year + mon + date
        }

        var nowDay = GDate();
        $('#Tradingday').val(nowDay);

        //查询条件交易日绑定日期事件
        $("#Tradingday--不用控件了").datetimepicker({
            format: 'yyyymmdd',
            startView: 'year',
            maxView: 'year',
            minView: 'month',
            autoclose: true,
            pickerPosition: "bottom-right",
            language: 'zh',
            bootcssVer: 3, //显示箭头
        });


        //查询
        function orderSearchSelect() {
            var Tradingday = $("#Tradingday").val();
            var RuleID = $("#RuleID").val();
            var OrderInnerID = $("#OrderInnerID").val();
            var AccountID = $("#AccountID").val();
            var InstrumentID = $("#InstrumentID").val();
            var OrderStatus = $("#OrderStatus").val();
            //判断交易日是否为空，格式是否正确
            $('#tradingdaySpanInfo').text('');
            if (Tradingday.length !== 8) {
                console.log(Tradingday, Tradingday.length);
                $('#tradingdaySpanInfo').text('日期格式错误，日期格式为：yyyymmdd');
                return;
            }
            // 整理发送后台的数据
            var data = {
                "Tradingday": Tradingday,
                "RuleID": RuleID,
                "OrderInnerID": OrderInnerID,
                "AccountID": AccountID,
                "InstrumentID": InstrumentID,
                "OrderStatus": OrderStatus,
            };

            var JsonData = JSON.stringify(data);
            $.post("{% url 'Manager:order_list' %}", {"data": JsonData, 'orderSearch_select': 1}, function (r) {
                console.log(r);
                $("#OrderSearch").bootstrapTable("destroy").bootstrapTable({
                    height: 600,
                    columns: [
                        {
                            field: 'tradingday',
                            width: 80,
                            title: '交易日',
                            color: 'red',

                        }, {
                            field: 'ruleid',
                            width: 80,
                            title: '策略编号'
                        }, {
                            field: 'orderinnerid',
                            title: '报单内部编号',
                            width: 80,
                        }, {
                            field: 'ordersysid',
                            title: '报单编号',
                            width: 60,
                        }, {
                            field: 'accountid',
                            title: '交易账号',
                            width: 60,
                        }, {
                            field: 'instrumentid',
                            title: '合约代码',
                            width: 60,
                        }, {
                            field: 'instrumentname',
                            title: '合约名称',
                            width: 60,
                        }, {
                            field: 'direction',
                            title: '买卖',
                            width: 60,
                            cellStyle: function (value) {
                                if (value === '买') {

                                    return {css: {"color": 'red'}}

                                } else if (value === '卖') {

                                    return {css: {'color': 'green'}}

                                }

                                return;

                            }


                        }, {
                            field: 'offsetflag',
                            title: '开平',
                            width: 60,
                        }, {
                            field: 'orderstatus',
                            title: '挂单状态',
                            width: 60,
                            cellStyle: function (value, row, index) {
                                console.log(value);
                                if (value === '全部成交') {
                                    return {css: {'color': 'rgb(0, 176, 80)'}}
                                } else if (value === '部分成交') {
                                    return {css: {'color': 'rgb(247, 150, 70)'}}
                                } else if (value === '未成交') {
                                    return {css: {'color': 'rgb(112,173,71)'}}
                                } else if (value === '废单') {
                                    return {css: {'color': 'rgb(255, 82, 82)'}}
                                } else if (value === '自成交废单') {
                                    return {css: {'color': 'rgb(255, 82, 82)'}}
                                } else if (value === '撤单') {
                                    return {css: {'color': 'rgb(75, 172, 198)'}}
                                } else {
                                    return {css: {'color': 'rgb(0,0,0)'}}
                                }
                                return;
                            },

                        }, {
                            field: 'price',
                            title: '报单价格',
                            width: 60,
                        }, {
                            field: 'volume',
                            title: '报单手数',
                            width: 60,
                        }, {
                            field: 'volumetotal',
                            title: '未成交手数',
                            width: 60,
                        }, {
                            field: 'volumetraded',
                            title: '成交手数',
                            width: 60,
                        }, {
                            field: 'statusmsg',
                            title: '详细状态',
                            width: 60,
                        }, {
                            field: 'inserttime',
                            title: '报单时间',
                            width: 60,
                        }, {
                            field: 'updatetime',
                            title: '更新时间',
                            width: 60,
                        }, {
                            field: 'assetno',
                            title: '资金账号',
                            width: 60,
                        }, {
                            field: 'combino',
                            title: '组合编号',
                            width: 60,
                        }, {
                            field: 'quotetype',
                            title: '报单类型',
                            width: 60,
                        }, {
                            field: 'commoditytype',
                            title: '报单种类',
                            width: 60,
                        }, {
                            field: 'bilateralid',
                            title: '双边报价编号',
                            width: 60,
                        }

                    ],
                    data: r,
                    // height: 600,
                    // width: 100,
                    //******前端分页设置****
                    pagination: true,
                    pageNumber: 1,
                    pageSize: 20,
                    pageList: [10, 20, 50, 100],
                    paginationHAlign: "right",
                    paginationDetailHAlign: "left"
                    //******前端分页设置****
                });
            });

        }

        //bstable渲染页面（固定写法）
        function InitBootstrapTable(my_url, my_table_id, my_columns, my_filename, tab_type, req_type) {
            $('#' + my_table_id).bootstrapTable('destroy').bootstrapTable({
                url: my_url,
                method: 'get',
                columns: my_columns,
                toolbar: '#toolbar',
                striped: true,
                cache: false,
                pagination: true,
                sortable: true,
                height: 600,
                sortOrder: "asc",
                queryParams: function (pageRequest) {
                    pageRequest['tab_type'] = tab_type;
                    pageRequest['req_type'] = req_type;
                    return pageRequest;
                },
                sidePagination: "server",
                pageNumber: 1,
                pageSize: 20,
                pageList: [10, 25, 50, 100],
                {#search: true,#}
                {#            strictSearch: false,#}
                {#    showColumns: true,      #}
                {#            showRefresh: true,      #}
                minimumCountColumns: 2,
                clickToSelect: true,
                uniqueId: "_id",
                {#    showToggle: true,    #}
                cardView: false,
                detailView: false,
                {#    showExport: true,#}
                buttonsAlign: "right",
                {#exportDataType: "all",#}
                {#            exportTypes: ['excel'],#}
                {#            Icons: 'glyphicon-export',#}
                {#            exportOptions: {#}
                {#              fileName: my_filename,#}
                {#            },#}
            })
        }

        // 报单查询
        my_columns = [
            {
                field: 'Tradingday',
                width: 80,
                title: '交易日',
                color: 'red',

            }, {
                field: 'RuleID',
                width: 80,
                title: '策略编号'
            }, {
                field: 'OrderInnerID',
                title: '报单内部编号',
                width: 80,
            }, {
                field: 'OrderSysID',
                title: '报单编号',
                width: 60,
            }, {
                field: 'AccountID',
                title: '交易账号',
                width: 60,
            }, {
                field: 'InstrumentID',
                title: '合约代码',
                width: 60,
            }, {
                field: 'InstrumentName',
                title: '合约名称',
                width: 60,
            }, {
                field: 'Direction',
                title: '买卖',
                width: 60,
                cellStyle: function (value, row, index) {

                    if (value === '买') {

                        return {css: {"color": 'red'}}

                    } else if (value === '卖') {

                        return {css: {'color': 'green'}}

                    }

                },
            }, {
                field: 'OffSetFlag',
                title: '开平',
                width: 60,
            }, {
                field: 'OrderStatus',
                title: '挂单状态',
                width: 60,
                cellStyle: function (value, row, index) {
                    console.log(value);
                    if (value === '全部成交') {
                        return {css: {'color': 'rgb(0, 176, 80)'}}
                    } else if (value === '部分成交') {
                        return {css: {'color': 'rgb(247, 150, 70)'}}
                    } else if (value === '未成交') {
                        return {css: {'color': 'rgb(112,173,71)'}}
                    } else if (value === '废单') {
                        return {css: {'color': 'rgb(255, 82, 82)'}}
                    } else if (value === '自成交废单') {
                        return {css: {'color': 'rgb(255, 82, 82)'}}
                    } else if (value === '撤单') {
                        return {css: {'color': 'rgb(75, 172, 198)'}}
                    } else {
                        return {css: {'color': 'rgb(0,0,0)'}}
                    }
                },

            }, {
                field: 'Price',
                title: '报单价格',
                width: 60,
            }, {
                field: 'VolumeTotalOriginal',
                title: '报单手数',
                width: 60,
            }, {
                field: 'VolumeTotal',
                title: '未成交手数',
                width: 60,
            }, {
                field: 'VolumeTraded',
                title: '成交手数',
                width: 60,
            }, {
                field: 'OrderStatusMsg',
                title: '详细状态',
                width: 60,
            }, {
                field: 'InsertTime',
                title: '报单时间',
                width: 60,
            }, {
                field: 'UpdateTime',
                title: '更新时间',
                width: 60,
            }, {
                field: 'AssetNo',
                title: '资金账号',
                width: 60,
            }, {
                field: 'CombiNo',
                title: '组合编号',
                width: 60,
            }, {
                field: 'QuoteType',
                title: '报单类型',
                width: 60,
            }, {
                field: 'CommodityType',
                title: '报单种类',
                width: 60,
            }, {
                field: 'BilateralID',
                title: '双边报价编号',
                width: 60,
            }
        ];

        //渲染table数据
        InitBootstrapTable("{{url}}", "OrderSearch", my_columns, "OrderTableFileName", '0', "1");
    </script>

{% endblock %}